package com.slipper.system.message;

import javax.annotation.Resource;

import com.slipper.common.permit.PermitAll;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.slipper.system.api.message.bo.MessageBO;
import com.slipper.system.api.message.service.IMessageSv;
import com.slipper.system.common.Constants;
import com.slipper.common.util.ResultUtil;

/**
 * 消息信息表
 * 
 * @date 2023-03-15 15:53:45
 */
@RestController
@RequestMapping("/message")
public class MessageController {
    @Resource
    private IMessageSv messageSv;
    
    @PostMapping(value = "/queryBy")
    public String queryBy(@RequestBody MessageBO bo) {
        if(bo.getId() == null || "".equals(bo.getId())) {
            return ResultUtil.toErrorJson("数据获取失败！");
        }
        return ResultUtil.toJson(messageSv.queryBy(bo.getId()));
    }

    @PostMapping(value = "/queryList")
    public String queryList(@RequestBody MessageBO bo) {
        return ResultUtil.toJson(messageSv.queryList(bo));
    }
    
    @PostMapping(value = "/queryPage")
    public String queryPage(@RequestBody MessageBO bo) {
        if (!Constants.getCurrentUser().isSuperAdmin()) {
            bo.setCreateId(Constants.getCurrentUser().getEmployeeId());
        }
        return ResultUtil.toJson(messageSv.queryPage(bo));
    }

    @PostMapping(value = "/save")
    public String save(@RequestBody MessageBO bo) {
        bo.setUpdateId(Constants.getCurrentUser().getEmployeeId());
        bo.setCreateId(Constants.getCurrentUser().getEmployeeId());
        return ResultUtil.toJson(messageSv.save(bo));
    }

    @PostMapping(value = "/delete")
    public String delete(@RequestBody MessageBO bo) {
        return ResultUtil.toJson(messageSv.delete(bo));
    }

    @PermitAll
    @PostMapping(value = "/queryMyPage")
    public String queryMyPage(@RequestBody MessageBO bo) {
        bo.setEmployeeId(Constants.getCurrentUser().getEmployeeId());
        return ResultUtil.toJson(messageSv.queryMyPage(bo));
    }

    @PermitAll
    @PostMapping(value = "/queryMyCount")
    public String queryMyCount(@RequestBody MessageBO bo) {
        bo.setEmployeeId(Constants.getCurrentUser().getEmployeeId());
        return ResultUtil.toJson(messageSv.queryMyCount(bo));
    }

    @PermitAll
    @PostMapping(value = "/updateRead")
    public String updateRead(@RequestBody MessageBO bo) {
        bo.setEmployeeId(Constants.getCurrentUser().getEmployeeId());
        return ResultUtil.toJson(messageSv.updateRead(bo));
    }
}
